package control

import (
	"fmt"
	"net/http"
	"pro_cla_sql/model"
	"pro_cla_sql/util"
	"strconv"
)

func Sapply(w http.ResponseWriter, r *http.Request) {
	w.Header().Set(`Content-Type`, `application/json`)
	w.Header().Set(`Access-Control-Allow-Origin`, `*`)
	cid := CSno[0:10]
	println(cid[0:10])
	// print(sno)
	mod, err := model.SapplysAll(cid)
	if err != nil {
		w.Write(util.NewResult(util.Fail, "奖学金信息查询失败"))
		return
	} else {
		w.Write(util.NewResult(util.Success, "奖学金信息查询成功", mod))
		return
	}

}
func Sapplysadd(w http.ResponseWriter, r *http.Request) {
	w.Header().Set(`Content-Type`, `application/json`)
	w.Header().Set(`Access-Control-Allow-Origin`, `*`)

	r.ParseForm()
	// map
	var sno = CSno
	var type1 = r.FormValue("type1")
	var content = r.FormValue("content")
	var sex = r.FormValue("sex")
	acid := sno[0:10]

	var bukao = r.FormValue("bukao")
	var score_asc = r.FormValue("score_asc")
	abukao, _ := strconv.Atoi(bukao)
	ascore_asc, _ := strconv.Atoi(score_asc)

	_, sname, sex, tel, ainfocunt, _ := model.SinfosOne(sno)
	fmt.Println(sname)

	cid, _ := strconv.Atoi(acid)

	ok := model.SapplyAdd(sno, sname, type1, content, sex, tel, ainfocunt, abukao, ascore_asc, cid)
	if ok {
		w.Write(util.NewResult(util.Success, "申请成功"))
	} else {
		w.Write(util.NewResult(util.Fail, "申请失败"))
	}

}
